<template>
	<view class="wrap">
		<!-- 	<view class="search">
			<u-search v-model="keywords" @custom="search" @search="search"></u-search>
		</view> -->
		<u-form class="form" :model="model" ref="uForm" label-position="left">
			<u-form-item label="id" label-width="180" v-if="model.id"><u-input placeholder="id" v-model="model.id" type="text" maxlength="64"></u-input></u-form-item>
			<!-- <u-form-item label="任务年度" label-width="180">
				<js-select v-model="model.taskYear" :label-value="model.taskYear" @label-input="model.taskYear = $event" dict-type="task_year"></js-select>
			</u-form-item> -->
			<u-form-item label="任务年度" label-width="180">
				<js-select
					v-model="model.taskYear"
					:items="yearList"
					placeholder="请选择任务年度"
					
					@confirm="getYear1(arguments)"
					:label-value="model.taskYearName"
					@label-input="model.taskYear = $event"
				></js-select>
			</u-form-item>
			<u-form-item label="任务类型" label-width="180">
				<js-select
					v-model="model.taskTypeCode"
					:items="typeSelectList"
					placeholder="请选择任务类型"
					
					@confirm="getTaskType(arguments)"
					:label-value="model.taskTypeName"
					@label-input="model.taskTypeCode = $event"
				></js-select>
			</u-form-item>
			<u-form-item label="任务标题" label-width="180"><u-input placeholder="请输入任务标题" v-model="model.taskTitle" type="text" maxlength="200"></u-input></u-form-item>
			<u-form-item label="任务分类" label-width="180">
				<js-select
					v-model="model.taskCreateType"
					:items="typeQueryList"
					placeholder="请选择任务分类"
					
					@confirm="getQueryType(arguments)"
					:label-value="model.taskCreateName"
					@label-input="model.taskCreateType = $event"
				></js-select>
			</u-form-item>
			<u-form-item label="牵头领导" label-width="180">
				<js-select
					v-model="model.taskLeader"
					:items="userSelectList"
					placeholder="请选择牵头领导"
					
					@confirm="getLeaderOrg(arguments)"
					:label-value="model.taskLeaderName"
					@label-input="model.taskLeader = $event"
				></js-select>
			</u-form-item>

			<u-form-item label="任务进度" label-width="180"><js-radio v-model="model.taskProgress" dict-type="dc_task_progress"></js-radio></u-form-item>
		</u-form>
		<view class="uni-flex" style="-webkit-justify-content: flex-end;justify-content: flex-end;margin-bottom: 10rpx;">
			<u-button type="primary" style="margin-top: 25rpx; width: 30%; margin-bottom: 4rpx" @click="doQuery" :plain="true" :hairline="true" text="查询">查询</u-button>
			<u-button type="primary" style="margin-top: 25rpx; width: 30%; margin-bottom: 4rpx" @click="resetAll" :plain="true" :hairline="true" text="重置">重置</u-button>
		</view>
		<scroll-view class="scroll-list" scroll-y="true" @scrolltolower="loadMore">
			<u-cell-group class="list" :border="false">
				<u-swipe-action v-for="(item, index) in list" :key="item.id" :index="index" @click="optionsClick">
					<u-cell-item :arrow="true" @click="navTo('taskAccountDetails?id=' + item.id)" style="border-bottom: 1px solid #ededed">
						<text slot="title">{{ item.taskTitle || item.id }}</text>
						<text slot="label">
							任务类型：{{ item.taskTypeName }}
							<br />
							任务进度：{{ item.taskStatusStr }}
						</text>
						<text slot="label"></text>
					</u-cell-item>
				</u-swipe-action>
			</u-cell-group>
			<view class="loadmore" @click="loadMore"><u-loadmore :status="loadStatus"></u-loadmore></view>
		</scroll-view>
	</view>
</template>
<script>
/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
export default {
	data() {
		return {
			model: {
				id: '',
				pageNo: 1,
				pageSize: 20,
				taskYear: '',
				taskYearName: '',
				taskTypeCode: '',
				taskTypeName: '',
				taskTitle: '',
				taskContent: '',
				taskLeader: '',
				taskLeaderName: '',
				taskProgress: '',

				taskleader: {
					userCode: '',
					userName: ''
				}
			},
			keywords: '',
			list: [],
			count: 0,
			loadStatus: 'loadmore',
			options: [{ text: '删除', style: { background: '#dd524d' } }],
			officeSelectList: [],
			userSelectList: [],
			typeSelectList: [],
			yearList: [],
			typeQueryList: [{name:'单位发布的任务',value:'2'},{name:'我发布的任务',value:'1'},{name:'单位接收的任务',value:'4'},{name:'我接收的任务',value:'3'}],
		};
	},
	onLoad(params) {
		this.model.taskYear = new Date().getFullYear();
		this.model.taskCreateType = 2;
	},
	onReady() {
		this.$u.api.taskInfo.getDict().then(res => {
			res.data.map(item => {
				this.typeSelectList.push({
					name: item.dictLabel,
					value: item.dictValue
				});
			});
		});
		this.$u.api.taskInfo.getYear().then(res => {
			res.data.map(item => {
				this.yearList.push({
					name: item.dictLabel,
					value: item.dictValue
				});
			});
		});
		this.$u.api.taskInfo.getLeader().then(res => {
			res.data.map(item => {
				this.userSelectList.push({
					name: item.refName,
					value: item.refCode
				});
			});
		});
		// 机构数据
		this.$u.api.office.treeData().then(res => {
			this.officeSelectList = res;
		});
		this.doQuery();
	},
	onShow() {
		if (uni.getStorageSync('refreshList') === true) {
			uni.removeStorageSync('refreshList');
			this.search('');
		}
	},
	methods: {
		doQuery() {
			this.model.pageNo = 0;
			this.list = [];
			this.loadList();
		},
		change(value) {
			this.model.taskTypeCode = value;
		},
		getLeaderOrg(value) {
			if(value.length > 1){
			this.model.taskLeader = value[0];
			this.model.taskLeaderName = value[1];	
			}else{
				this.model.taskLeader = value[0].label;
				this.model.taskLeaderName = value[0].value;
			}
			
		},
		getTaskType(val) {
			this.model.taskTypeCode = val[0];
			this.model.taskTypeName = val[1];
		},
		getQueryType(val) {
			this.model.taskCreateType = val[0];
		},
		getYear1(val) {
			console.log(111)
			this.model.taskYear = val[0];
		},
		resetAll() {
			this.model.taskContent = '';
			this.model.taskLeader = '';
			this.model.taskProgress = '';
			this.model.taskYear = new Date().getFullYear();
			this.model.taskTitle = '';
			this.model.taskTypeCode = '';
			this.model.taskLeaderOrg = '';
			this.model.taskTypeName = '';
			this.model.taskLeaderName = '';
			this.list = [];
			this.loadList();
		},
		loadMore() {
			this.loadStatus = 'loading';
			setTimeout(() => {
				this.model.pageNo += 1;
				this.loadList();
			}, 100);
		},

		cancel() {
			uni.navigateBack();
		},
		loadList() {
			this.$u.api.taskAccount.list(this.model).then(res => {
				for (var i = 0; i < res.list.length; i++) {
					if (res.list[i].taskStatus == 2) {
						res.list[i].taskStatusStr = '已发布';
					}
					if (res.list[i].taskStatus == 3) {
						res.list[i].taskStatusStr = '任务部署审核通过';
					}
					if (res.list[i].taskStatus == 4) {
						res.list[i].taskStatusStr = '任务部署审核驳回';
					}
					if (res.list[i].taskStatus == 5) {
						res.list[i].taskStatusStr = '秘书长审核通过';
					}
					if (res.list[i].taskStatus == 6) {
						res.list[i].taskStatusStr = '秘书长审核驳回';
					}
					if (res.list[i].taskStatus == 7) {
						res.list[i].taskStatusStr = '已确认';
					}
					if (res.list[i].taskStatus == 8) {
						res.list[i].taskStatusStr = '进行中';
					}
					if (res.list[i].taskStatus == 9) {
						res.list[i].taskStatusStr = '已结束';
					}
				}
				if (!res.list || res.list.length == 0) {
					this.loadStatus = 'nomore';
					return;
				}
				this.list = this.list.concat(res.list);
				this.count = res.count;
				this.model.pageNo = res.pageNo;
				this.model.pageSize = res.pageSize;
				this.loadStatus = 'loadmore';
			});
		},
		optionsClick(rowIndex, btnIndex) {
			if (btnIndex == 0) {
				let self = this;
				uni.showModal({
					title: '提示',
					content: '确认要删除该数据吗？',
					showCancel: true,
					success: function(res2) {
						if (res2.confirm) {
							let row = self.list[rowIndex];
							self.$u.api.testData.delete({ id: row.id }).then(res => {
								self.$u.toast(res.message);
								if (res.result == 'true') {
									self.list.splice(rowIndex, 1);
								}
							});
						}
					}
				});
			}
		},
		search(value) {
			this.list = [];
			this.model.pageNo = 0;
			this.model.testInput = value;
			this.loadList();
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		}
	}
};
</script>
<style lang="scss">
page {
	background-color: #f8f8f8;
}
.btn-plus {
	position: absolute;
	bottom: 50rpx;
	right: 50rpx;
	z-index: 1;
	opacity: 0.6;
}
.btn-plus:hover {
	opacity: 1;
}
.text {
	margin: 15rpx 10rpx;
	padding: 0 20rpx;
	background-color: #ebebeb;
	height: 70rpx;
	line-height: 70rpx;
	text-align: center;
	color: #777;
	font-size: 26rpx;
}
.uni-flex {
	display: flex;
	flex-direction: row;
}
</style>
